package com.tianpengtech.front.web.main;

import com.tianpengtech.common.model.fair.Fair;
import com.tianpengtech.common.model.task.Task;
import com.tianpengtech.common.model.task.TaskWh;

import java.util.List;

/**
 * Created by ggd on 2017/6/14 0014.
 */
public class MainService {
    private Fair fair = Fair.dao;
    private TaskWh taskWh = TaskWh.dao;
    private Task task = Task.dao;
    /**
     * 获取主页面网红信息
     * @return
     */
    public List<Fair> mainFair(){
//        String sql = "select tw.*,fair.*,SUM(tw."+TaskWh.CLICK_NUM+") cnum,SUM(tw."+TaskWh.CVS_NUM+") cnum,COUNT(tw."+TaskWh.WH_ID+") count from "+taskWh.tableName()+" tw left join "+fair.tableName()+" fair on fair."+fair.ID+"=tw."+TaskWh.WH_ID+" GROUP BY "+TaskWh.WH_ID+" ORDER by SUM("+TaskWh.CLICK_NUM+") desc,SUM("+TaskWh.CVS_NUM+") desc,COUNT("+TaskWh.WH_ID+") desc LIMIT 3";
//        List<Fair> fairs=fair.findByCache(Fair.FAIR_CACHE_NAME,"main_fair",sql);
//    	
    	String sql="select * from "+Fair.dao.tableName()+" where "+Fair.STATUS+"=? order by "+Fair.ID+" desc limit 3";
    	List<Fair> fairs= Fair.dao.find(sql,Fair.STATUS_SUCCESS);
        return fairs;
    }

    /**
     * 首页任务
     * @return
     */
    public List<Task> mainTask(long user){
        String sql ="select * from "+Task.dao.tableName()+" where "
        		+Task.CREATE_USER+"=? and "+Task.STATUS+" in (?,?,?) order by "+Task.ID +" desc limit 6";
//        List<Task> tasks=task.findByCache(Task.TASK_CACHE_NAME,"main_task",sql);
        List<Task> tasks=task.find(sql,user,Task.STATUS_SUCCESS,Task.STATUS_START,Task.STATUS_APPROVING);
        return tasks;
    }




}
